package com.xlh.enums.courseTest;

import com.google.common.collect.Maps;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Map;
import java.util.Objects;

/**
 * @author zhr 2019/4/18
 */
@Getter
@AllArgsConstructor
public enum StudentStatusEnum {
    BASE_TEST(1, "理论题", "正在考试"),
    EXPERIMENT_TEST(2, "实验题", "正在考试"),
    SUBMITTED(3, "已交卷", "待批阅"),
    ENDED(4, "考试已结束", "已批阅");

    private final Integer status;
    private final String message;
    private final String checkMessage;

    private static Map<Integer, StudentStatusEnum> statusLookup = Maps.newHashMap();

    static {
        for (StudentStatusEnum statusEnum : StudentStatusEnum.values()) {
            statusLookup.put(statusEnum.getStatus() , statusEnum);
        }
    }

    public static StudentStatusEnum forCode(Integer code) {
        return statusLookup.get(code);
    }

    public static StudentStatusEnum getStudentStatusEnum(AnswerSheetStatusEnum answerSheetStatusEnum, PaperStatusEnum paperStatusEnum) {
        if (paperStatusEnum.notEnd()) {
            if (answerSheetStatusEnum.isBase()) return BASE_TEST;
            else if (answerSheetStatusEnum.isExperiment()) return EXPERIMENT_TEST;
            else return SUBMITTED;
        } else {
            return ENDED;
        }
    }

    public boolean isTesting(){
        return Objects.equals(this, BASE_TEST) || Objects.equals(this, EXPERIMENT_TEST);
    }
}
